home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 7
/
FM Towns Free Software Collection 7.iso
/
taropyon
/
zmodem
/
src
/
flib.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-11-30
|
1KB
|
81 lines
#include <stdio.h>
#include <stdlib.h>
#include <fslib.h>
#include "flib.h"
static FFPLST_T *FfpTop = NULL;
#ifndef MALLOC
# define MALLOC malloc
#endif
#ifndef FREE
# define FREE free
#endif
FILE *FM_fopen(CONST char *fn, CONST char *md)
{
FFPLST_T *ffp;
FILE *fp;
fp = FS_fopen(fn,md);
if ( fp == NULL )
return (NULL);
if ( (ffp = MALLOC(sizeof(FFPLST_T))) == NULL )
return (fp);
ffp->next = ffp->prev = NULL;
ffp->fp = fp;
if ( *md == 'w' || *md == 'a' )
ffp->md = 1;
else
ffp->md = 0;
ffp->drv = ERR;
if ( FS_setFullPathName( ffp->fn, (char *)fn ) == NORMAL )
ffp->drv = toupper(ffp->fn[0]) - 'A';
if ( FfpTop == NULL )
{
FfpTop = ffp;
} else
{
ffp->next = FfpTop;
FfpTop->prev = ffp;
FfpTop = ffp;
}
return (fp);
}
int FM_fclose( FILE *fp )
{
int ret;
FFPLST_T *ffp = FfpTop;
while ( ffp )
{
if ( ffp->fp == fp )
{
if ( ffp->prev ) ffp->prev->next = ffp->next;
if ( ffp->next ) ffp->next->prev = ffp->prev;
if ( ffp == FfpTop ) FfpTop = ffp->next;
FREE( ffp );
break;
}
ffp = ffp->next;
}
ret = FS_fclose(fp);
return (ret);
}
void FM_all_fclose(void)
{
while ( FfpTop )
{
FFPLST_T *ffp;
ffp = FfpTop;
FM_fclose( ffp->fp );
}
}